package net.sk.cam;

import org.apache.mina.core.buffer.IoBuffer;

public class FramePara {
	public static final int NUM_Para = 0x160;
	public static final int LEN_Para =NUM_Para*4;
	public static final int LEN_HEART = 4;
	
	String decodePara(IoBuffer in){
		byte[] f0 = new byte[4];
		in.get(f0);
		//heart response
		if(f0[0]==0xAA && f0[1]==0x55 && f0[2]==0xAA && f0[3]==0x55){
			return null;
		}
        if (in.remaining()<LEN_Para-4) {
        	return null;
        }
		StringBuffer sbuf = new StringBuffer();		
		int[] fi = new int[NUM_Para];
		byte[] fhb = new byte[LEN_Para];
		in.get(fhb);
		fi[0]=FrameHeader.byteArrayToInt(f0[0], f0[1], f0[2], f0[3]);
		for(int i=1; i<NUM_Para; i++){
			int pos = i*4;
			fi[i]=FrameHeader.byteArrayToInt(fhb[pos], fhb[pos+1], fhb[pos+2], fhb[pos+3]);
		}
		for(int i=0; i<NUM_Para; i++){
			sbuf.append("p"+i +"="+fi[i]);
		}
		return sbuf.toString();
	}
	
}
